import { LOGIN, ROUTES, REGISTER, USERINFO, CUSTOM_USERINFO } from './api';

import { VISITNUM } from './shopApi/api';
import { request, METHOD, removeAuthorization } from '@/utils/request';

/**
 * 登录服务
 * @param name 账户名
 * @param password 账户密码
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function login(phone, password) {
  return request(LOGIN, METHOD.POST, {
    phone,
    password,
  });
}

/**
 * 注册服务
 * @param
 *
 */
export async function register(name, phone, password) {
  return request(REGISTER, METHOD.POST, {
    name,
    phone,
    password,
    type: 2,
  });
}

/**
 * 获取自身信息
 *
 */
export async function userinfo() {
  return request(USERINFO, METHOD.GET);
}

/**
 * 获取客户信息
 *
 */
export async function getCustomerInfo(params) {
  return request(CUSTOM_USERINFO, METHOD.DYNAMIC, params);
}

/**
 * 更新用户信息
 *
 */
export async function updateUserInfo(params) {
  return request(CUSTOM_USERINFO, METHOD.PUT, params);
}

/**
 * 项目访问量
 *
 */
export async function getVisitNum(params) {
  return request(VISITNUM, METHOD.GET, params);
}

export async function getRoutesConfig() {
  return request(ROUTES, METHOD.GET);
}

/**
 * 退出登录
 */
export function logout() {
  localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY);
  localStorage.removeItem('permissions');
  localStorage.removeItem('roles');
  localStorage.removeItem('user');
  localStorage.removeItem('e-token');
  localStorage.removeItem('adminInfo');
  sessionStorage.clear();
  removeAuthorization();
}
export default {
  register,
  login,
  logout,
  getRoutesConfig,
  userinfo,
  getCustomerInfo,
  updateUserInfo,
  getVisitNum,
};
